package com.example.administrator.yuejian2.VLayoutAdapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.other.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

public class BannerAdapter extends DelegateAdapter.Adapter{

    private Context context;
    private static final String URl="http://10.0.2.2/YueJian02/posters/";
    private List<String> mListImage;
    private LayoutInflater layoutInflater;
    private LayoutHelper helper;
    private VirtualLayoutManager.LayoutParams layoutParams;
    public BannerAdapter(Context context,LayoutHelper helper)
    {
        this.layoutInflater=LayoutInflater.from(context);
        this.context=context;
        this.helper=helper;

    }
    public BannerAdapter(Context context,LayoutHelper helper,VirtualLayoutManager.LayoutParams layoutParams)
    {
        this.context=context;
        this.helper=helper;
        this.layoutParams=layoutParams;
    }
    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return helper;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=layoutInflater.inflate(R.layout.banner_item,parent,false);
        return new BannerViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BannerViewHolder viewHolder=(BannerViewHolder)holder;
        viewHolder.banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        viewHolder.banner.setImageLoader(new GlideImageLoader());
        mListImage = new ArrayList<>();
        mListImage.add(URl+"pic1.jpg");
        mListImage.add(URl+"pic2.jpg");
        mListImage.add(URl+"pic3.jpg");
        mListImage.add(URl+"pic4.jpg");
        viewHolder.banner.setImages(mListImage);
        viewHolder.banner.setBannerAnimation(Transformer.DepthPage);
        viewHolder.banner.setDelayTime(2000);
        viewHolder.banner.setIndicatorGravity(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
        viewHolder.banner.start();
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    class BannerViewHolder extends RecyclerView.ViewHolder
    {
        private Banner banner;
        public BannerViewHolder(View itemView) {
            super(itemView);
            banner=itemView.findViewById(R.id.banner_pic);
        }
    }
}
